
#include <scene/Quad.h>
#include <base/d3d.h>
#include <base/resourcemanager.h>
#include <event/events.h>

#include <vector>
#include <fstream>


//long ticks = 0;
//unsigned long lasttime;
//unsigned long lastcall;

//std::vector<unsigned long> values;
//bool writeit = true;

Quad::Quad() {
  x = 0.0f;
  y = 0.0f;
  width = 1.0f;
  height = 1.0f;
  theta = 0.0f;
}

Quad::Quad(const Quad * rhs) : SceneNode(rhs) {
  x = rhs->x;
  y = rhs->y;
  width = rhs->width;
  height = rhs->height;
  theta = rhs->theta;
}

// to be executed in main thread

long Quad::preDraw(Device * device) {
  device->drawRect(x, y, width, height, theta);
  return 0;
}

SceneNode * Quad::copy() const {
  return new Quad(this);
}

SceneNode * Quad::select(const D3DXVECTOR4 & v){
  char temp[128];
  //sprintf(temp, "quad: %f %f %f %f mouse: %f %f", x, y, width, height, v.x, v.y);
  //    events::Fire(new events::PrintConsole(temp));

  if(x - 0.5 * width <= v.x && x + 0.5 * width >= v.x &&
    y - 0.5 * height <= v.y && y + 0.5 * height >= v.y){
    return this;
  }else{
    return NULL;
  }
}
